// pages/violation/violationSearch/violationSearch.js
const util = require('../../../utils/util.js');

Page(Object.assign({

  /**
   * 页面的初始数据
   */
  data: {
    typeArray: ['小型车', '大型车'],
    typeIndex: 0,
    plate: '',
    engine: '',
    frame: '',

    isPanelShow:false,
    isPanelShow: false,
    keyBoardType: 1,
    licenceProvince: '粤',
    licenceCode: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  //车牌键盘的输入触发
  inputPaneChange: function (e) {
    let licenceCode = this.data.licenceCode;
    if (this.data.keyBoardType == 1) {
      this.setData({
        isPanelShow: false,
        licenceProvince: e.detail,
      });
    } else {
      if (licenceCode.length >= 6 || !e.detail) {
        return;
      }
      this.setData({
        licenceCode: `${licenceCode}${e.detail}`,
      });
    }
  },
  panelHide: function () {
    this.setData({
      isPanelShow: false,
    });
  },
  //车牌键盘删除触发
  inputPaneDelete: function () {
    let licenceCode = this.data.licenceCode.split('');
    licenceCode.pop();
    this.setData({
      licenceCode: licenceCode.join(''),
    });
  },
  //车牌键盘确认触发
  inputPaneOk: function () {
    this.setData({
      isPanelShow: false
    });
  },
  //显示车牌键盘
  onShowPanel: function (e) {
    const type = e.currentTarget.dataset.type;
    this.setData({
      isPanelShow: true,
      keyBoardType: type,
    });
  },


  /**
   *切换号牌类型
   */
  bindTypeChange(e) {
    this.setData({typeIndex: e.detail.value});
  },
  /**
   * 点击立即查询
   */
  submitForm() {
    let plate = `${this.data.licenceProvince}${this.data.licenceCode}`;
    let engine = this.data.engine;
    let frame = this.data.frame;
    if (plate == '') {
      wx.showToast({title: '请填写车牌号码', icon: 'none', duration: 2000});
    } else if (engine == '') {
      wx.showToast({ title: '请填写发动机号', icon: 'none', duration: 2000 });
    } else if (frame == '') {
      wx.showToast({ title: '请填写车架号', icon: 'none', duration: 2000 });
    } else {
      let typeId = this.data.typeIndex == 1 ? '01' : '02';
      wx.navigateTo({
        url: `/pages/violation/violationList/violationList?plate=${plate}&typeId=${typeId}&engine=${engine}&frame=${frame}`,
      });
    }
  }
}, util))